class RaceAiPathFinding extends UDKBot;

DefaultProperties
{
	bIsPlayer = true;
	bAdjustFromWalls = true;
}


function Vector NextLocation(Actor target, out int noPath)
{
	local Vector tempDest, leftLine;
	noPath=0;

	leftLine.Y = Pawn.GetCollisionRadius();
	leftLine = Vector((Rotator(leftLine)+Pawn.Rotation))*Pawn.GetCollisionRadius();
	if(FastTrace(target.Location+leftline,Pawn.Location+leftline) && FastTrace(target.Location-leftline,Pawn.Location-leftline))
    {
		//`log("Free run!");
		return target.Location;
    }

	NavigationHandle.SetFinalDestination(target.Location);
   
	FindNavMeshPath(target);
		
	// move to the first node on the path
	
	if( NavigationHandle.GetNextMoveLocation( TempDest, 200) )
	{
		// suggest move preparation will return TRUE when the edge's
		// logic is getting the bot to the edge point
			// FALSE if we should run there ourselves
		if (!NavigationHandle.SuggestMovePreparation( TempDest,self))
		{
			//`log("Getting by the edge!");
			return tempDest;					
		}
		//`log("Run yourself!");
		return tempDest;
	}
	//`log("No path!");
	noPath	 = 1;
	return tempDest;
}


function bool FindNavMeshPath(Actor target)
{
	// Clear cache and constraints (ignore recycling for the moment)
	NavigationHandle.PathConstraintList = none;
	NavigationHandle.PathGoalList = none;

	// Create constraints
	class'NavMeshPath_Toward'.static.TowardGoal( NavigationHandle,target );
	class'NavMeshGoal_At'.static.AtActor( NavigationHandle, target );

	// Find path
	return NavigationHandle.FindPath();
}